window.onload = () => {
    var chatroom_info = document.getElementById("chatroom-info");
    document.getElementById("chatroom-info-backbtn").onclick = () => {
        if (chatroom_info.style.display == "none") {
            chatroom_info.style.display = "flex";
        } else {
            chatroom_info.style.display = "none"
        }
    };

    var ws = new WebSocket('ws://0.0.0.0:43999');
    // 获取连接状态
    console.log('ws连接状态:' + ws.readyState);
    //监听是否连接成功
    ws.onopen = function () {
        console.log('ws连接状态:' + ws.readyState);
        //连接成功则发送一个数据
        ws.send('test1');
        console.log('sended!')
    }
    // 接听服务器发回的信息并处理展示
    ws.onmessage = function (data) {
        console.log('接收到来自服务器的消息:');
        console.log(data);
        //完成通信后关闭WebSocket连接
        ws.close();
    }
    // 监听连接关闭事件
    ws.onclose = function () {
        // 监听整个过程中websocket的状态
        console.log('ws连接状态:' + ws.readyState);
    }
    // 监听并处理error事件
    ws.onerror = function (error) {
        console.log(error);
    }

    var textarea = document.getElementById("chatting-writing-textarea");
    window.onkeyup = (event) => {
        if (event.keyCode == 13) {
            textarea.value
        }
    };
};